package com.genreate.util.xinyuan.shop;

import com.genreate.constant.CmdCommandConstant;
import com.genreate.util.linuxUtil.LinuxUtil;
import com.jcraft.jsch.Session;

/**
 * 商城APP系统 打包部署到linux
 *
 * @author LYS
 * @date 2025-01-06
 */
public class AppProd25 {
    public static final String serverIp = "192.168.8.25";
    public static final int port = 22;
    public static final String username = "root";
    public static final String password = "Data.2024";
    public static final Session session = LinuxUtil.createSession(serverIp, port, username, password);

    /**
     * 项目jar路径 不带 // 后缀
     */
    public static final String projectJarPath = "D:\\ideaProjects\\xinyuan\\shinerayappback";

    /**
     * 项目jar路径前缀 带 // 后缀
     */
    public static final String projectJarPathPrefix = projectJarPath + "\\";


    /**
     * linux jar路径前缀
     */
    public static final String linuxJarPathPrefix = "/home/datawarehouse/Project/docker/";

    public static void main(String[] args) {
        all();
    }

    public static void all() {
        /**
         * 1.git拉取最新代码
         * 2.git切换到当前分支
         * 3.打包
         */
        LinuxUtil.gitPackage(projectJarPath, "shop","prod-85");
//
//        system();
//        manage();
//        forum();
        shop();
//        job();
//        mq();
//        file();
//        gateway();
//        auth();
//        es();
//        view();
        session.disconnect();
    }

    /**
     * 前端模块
     */
    private static void view() {
        String localFilePath = "D:\\wxData\\wxMsg\\WeChat Files\\wxid_u9kughnafyqm21\\FileStorage\\File\\2025-06\\shineray(1).zip";
        String remoteFilePath = linuxJarPathPrefix + "/nginx/html/shineray.zip";
        String extractCommand = "unzip -o /home/datawarehouse/Project/docker/nginx/html/shineray.zip -d /home/datawarehouse/Project/docker/nginx/html/shineray";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, extractCommand);
    }

    /**
     * 登录模块
     */
    private static void auth() {
        String localFilePath = projectJarPathPrefix + "ruoyi-auth\\target\\ruoyi-auth.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/auth/jar/ruoyi-auth.jar";
        String dockerRestartCommand = "docker restart ruoyi-auth";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 网关模块
     */
    private static void gateway() {
        String localFilePath = projectJarPathPrefix + "ruoyi-gateway\\target\\ruoyi-gateway.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/gateway/jar/ruoyi-gateway.jar";
        String dockerRestartCommand = "docker restart ruoyi-gateway";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 文件模块
     */
    private static void file() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\ruoyi-file\\target\\ruoyi-modules-file.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/file/jar/ruoyi-modules-file.jar";
        String dockerRestartCommand = "docker restart ruoyi-modules-file";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 商城模块
     */
    private static void shop() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\shinerayApp-Shop\\target\\shinerayApp-Shop.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/shinerayApp-Shop/jar/shinerayApp-Shop.jar";
        String dockerRestartCommand = "docker restart shineray-shop";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 定时任务模块
     */
    private static void job() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\ruoyi-job\\target\\ruoyi-modules-job.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/job/jar/ruoyi-modules-job.jar";
        String dockerRestartCommand = "docker restart ruoyi-modules-job";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 消息队列模块
     */
    private static void es() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\shinerayApp-Es\\target\\shinerayApp-Es.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/shinerayApp-Es/jar/shinerayApp-Es.jar";
        String dockerRestartCommand = "docker restart shineray-es";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 消息队列模块
     */
    private static void mq() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\shinerayApp-Mq\\target\\shinerayApp-Mq.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/shinerayApp-Mq/jar/shinerayApp-Mq.jar";
        String dockerRestartCommand = "docker restart shineray-mq";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 社区模块
     */
    private static void forum() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\shinerayApp-Forum\\target\\shinerayApp-Forum.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/shinerayApp-Forum/jar/shinerayApp-Forum.jar";
        String dockerRestartCommand = "docker restart shineray-forum";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 用户模块
     */
    private static void system() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\ruoyi-system\\target\\ruoyi-modules-system.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/system/jar/ruoyi-modules-system.jar";
        String dockerRestartCommand = "docker restart ruoyi-modules-system";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }

    /**
     * 车系模块
     */
    private static void manage() {
        String localFilePath = projectJarPathPrefix + "ruoyi-modules\\shinerayApp-Manage\\target\\shinerayApp-Manage.jar";
        String remoteFilePath = linuxJarPathPrefix + "ruoyi/modules/shinerayApp-Manage/jar/shinerayApp-Manage.jar";
        String dockerRestartCommand = "docker restart shineray-manage";

        LinuxUtil.copyFileExecuteCommand(session, localFilePath, remoteFilePath, dockerRestartCommand);
    }
}
